$(function() {
	var $name = $(".u1"), $pwd = $(".u2"), $name_info = $("#name_info"), $pwd_info = $("#pwd_info"),$msg=$(".msg");
	$name.focus();
	$(".u3").click(function() {
		var phone = $.trim($name.val());
		var pwd = $.trim($pwd.val());
		if (phone == '' || phone.length == 0) {
			$name_info.addClass("warn").attr("title", "用户名不能为空");
			move();
			return;
		}
		if (pwd == '' || pwd.length == 0) {
			$pwd_info.addClass("warn").attr("title", "密码不能为空");
			move();
			return;
		}
		try {
			$.post("view/user/login", {'phone':phone,'pwd':pwd}, function(data) {
				if(data.code==0){
					window.location.href=getRootPath()+"/index.htm";
				}else{
					$msg.html("用户名或密码错误，请重新输入").show();
					move();
				}
			});
		} catch (e) {
			alert("请求出错，请稍后重试");
		}
	});
	$name.focus(function() {
		$msg.hide();
		$name_info.removeClass("warn").removeClass("ok").attr("title", "");
	});
	$pwd.focus(function() {
		$msg.hide();
		$pwd_info.removeClass("warn").removeClass("ok").attr("title", "");
	});
	function move(){
//		$(".lg_box").clearQueue();
		$(".lg_box").animate({left:"+=30"},"fast").animate({left:"-=60"},"fast").animate({left:"0"},"fast");
	}
	
	$(document).keypress(function(event){
		if(event.keyCode==13) {
			$(".u3").click();
		}
	});
});
function getRootPath() {
    var strFullPath = window.document.location.href;
    var strPath = window.document.location.pathname;
    var pos = strFullPath.indexOf(strPath);
    var prePath = strFullPath.substring(0, pos);
    var postPath = strPath.substring(0, strPath.substr(1).indexOf('/' ) + 1);
    return (prePath + postPath);
}